package guijavacommander.tasks;

import guijavacommander.tasks.Task;
import guijavacommander.tasks.ProgressListener;

import java.util.List;
import java.util.ArrayList;

/**
 * User: Deady
 * Date: 16.07.2009
 * Time: 11:40:48
 */
public abstract class AbstractTask implements Task  {

    private List<ProgressListener> listeners = new ArrayList<ProgressListener>();
    private List<DescriptionListener> descListeners = new ArrayList<DescriptionListener>();
    private boolean stopRequested;

    public void addProgressListener(ProgressListener l) {
        listeners.add(l);
    }

    public void fireProgressChanged(int currentProgress) {
        for (ProgressListener l : listeners) {
            l.progressUpdated(currentProgress);
        }
    }

    public void addDescriptionListener(DescriptionListener l) {
        descListeners.add(l);
    }

    public void requestStop() {
        stopRequested = true;
    }

    public boolean isStopRequested() {
        return stopRequested;
    }

    public void fireDescriptionChanged(String description) {
        for (DescriptionListener l : descListeners) {
            l.descriptionUpdated(description);
        }
    }
}
